<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<div id=container>
  <span id=el>
  </span>
</div>
<script>
description('Test that DOMSubtreeModified listeners cannot cause TreeOrderedMap to be incorrect');

var counter = 0;
var container = document.getElementById('container');
var el = document.getElementById('el');
function broken() {
   if (++counter > 2) {
       document.removeEventListener('DOMSubtreeModified', broken, true);
       return;
   } else if (counter == 1)
       container.textContent = '';
   else
       container.appendChild(el);
}

document.addEventListener("DOMSubtreeModified", broken, true);
broken();
shouldBeTrue("document.contains(el)");
el.parentNode.removeChild(el);
el = null;
gc();
shouldBeNull("document.getElementById('el')");
</script>
